package com.itheima.order.controller;

import com.itheima.order.Pojo.Order;
import com.itheima.order.service.OrderService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @GetMapping("/order/{id}")
    public Order getOrder(@PathVariable Long id) {
        Order order = orderService.getOrder(id);

        Map<String, Object> map = new HashMap<>();
        map.put("userId",order.getUserId());
        map.put("orderNum",order.getNum());

        rabbitTemplate.convertAndSend("itcast.topic","red",map);
        return order;
    }
}
